﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using BUS;
using DTO;

namespace DuanGiuaKy
{
    public partial class ctrlU_adm_qlCTDT : UserControl
    {
        public ctrlU_adm_qlCTDT()
        {
            InitializeComponent();
        }
        private void loadDataGridView()
        {
            dgvCTDT.DataSource = CTDT_BUS.loadDanhSachCTDT();
        }
        private void ctrlU_adm_qlCTDT_Load(object sender, EventArgs e)
        {
            loadDataGridView();
        }

        private void tSBtnThemMoi_Click(object sender, EventArgs e)
        {
            frm_adm_CTDT qlCTDT = new frm_adm_CTDT();
            qlCTDT.ShowDialog();
            loadDataGridView();
        }

        private void tSBtnSuaThongTin_Click(object sender, EventArgs e)
        {
            string mactdt = dgvCTDT.CurrentRow.Cells[0].Value.ToString();
            string tenctdt = dgvCTDT.CurrentRow.Cells[1].Value.ToString();
            frm_adm_CTDT qlCTDT = new frm_adm_CTDT(mactdt, tenctdt);
            qlCTDT.ShowDialog();
            loadDataGridView();
        }

        private void tSBtnXoa_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Bạn có muốn xóa không?", "Cảnh báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (res == DialogResult.OK)
            {
                string mactdt = dgvCTDT.CurrentRow.Cells[0].Value.ToString();
                CTDT_BUS.XoaCTDT(mactdt);
                loadDataGridView();
            }
        }
    }
}
